<?php

namespace App\Common\Tools;


/**
 * Class Push
 * @package App\Common\Tools
 */
class ImageUrl
{
    /**
     * 返回
     * @param $urls
     * @access public make
     * @return array|string
     * @author shaowei
     */
    public static function make($urls)
    {
        if(is_array($urls)){
            $data = [];
            foreach ((array)$urls as $url)
            {
                $data[] = self::run($url);
            }
            return $data;
        }else{
            return self::run($urls);
        }
    }

    /**
     * 替换
     * @param $url
     * @access public run
     * @return string
     * @author shaowei
     */
    public static function run($url)
    {
        $preg = "/^http(s)?:\\/\\/.+/";
        if(preg_match($preg,$url) || empty($url))
        {
            return $url;
        } else {
            return env('BASE_URL').$url . '?imageslim';
        }
    }

    public static function makes($urls)
    {
        if(is_array($urls)){
            $data = [];
            foreach ((array)$urls as $url)
            {
                $data[] = self::img($url);
            }
            return $data;
        }else{
            return self::img($urls);
        }
    }
    /**
     * 替换
     * @param $url
     * @access public run
     * @return string
     * @author shaowei
     */
    public static function img($url)
    {
        return $url . '?imageslim';
    }


    /**
     * 文件
     * @param $url
     * @access public run
     * @return string
     * @author shaowei
     */
    public static function file($url)
    {
        $preg = "/^http(s)?:\\/\\/.+/";
        if(preg_match($preg,$url) || empty($url))
        {
            return $url;
        } else {
            return env('BASE_URL').$url ;
        }
    }
}
